package com.example.ssm1.service.impl;

import com.example.ssm1.exception.BusinessException;
import com.example.ssm1.mapper.UserMapper;
import com.example.ssm1.model.User;
import com.example.ssm1.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@AllArgsConstructor
public class UserServiceImpl implements IUserService {

    private final UserMapper userMapper;

    @Override
    public List<User> getUserList() {

        return userMapper.getUserList();
    }

    @Override
    public User getUserByName(String username, String password) throws BusinessException {
        User user= userMapper.getUserByName(username);
        if(user==null){
            throw new BusinessException("用户不存在",500);
        }

        if(!password.equals(user.getPassword())){
            throw new BusinessException("密码错误",500);
        }
        return user;
    }

    @Override
    public User getUserDetail(Integer id) {

        return  userMapper.getUserDetail(id);
    }
}
